import urllib.request as ur
import user_agent
import lxml.etree as le
import json


# 弄request
request = ur.Request(
    url='https://edu.csdn.net/teach_course/detail/68',
    headers={
        'Cookie': 'TY_SESSION_ID=86693760-2f93-4348-a02b-c656eaf3ae8f; uuid_tt_dd=10_20345766140-1557466352010-151600; dc_session_id=10_1557466352010.906982; c-login-auto=1; acw_tc=2760822115706908380864227ec1eede7e2af9d4dc6331b0d633a028186738; ADHOC_MEMBERSHIP_CLIENT_ID1.0=b4f4e84f-54aa-761c-f959-0fd68ec18616; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1570690759,1570697017,1570758977; SESSION=9131faf8-5582-4652-ad90-cd557f311a34; UserName=Stannis; UserInfo=34ef7e80fe2044fba59c9e317f4b6e80; UserToken=34ef7e80fe2044fba59c9e317f4b6e80; UserNick=Stannis; AU=808; UN=Stannis; BT=1570778173186; p_uid=U000000; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1570778093; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_20345766140-1557466352010-151600!5744*1*Stannis; dc_tos=pz784s',
        'User-Agent': user_agent.get_user_agent_pc(),
    }
)

response = ur.urlopen(request).read().decode('utf-8')
with open('response.html', 'w', encoding='utf-8') as f:
    f.write(response)

title = le.HTML(response).xpath('//h5[@class="content_title"]/text()')
